﻿using System;
using System.Collections.Generic;
using System.Linq;
//using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BL;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;

namespace WebsiteBanHang
{
    public partial class QuanLyUser : System.Web.UI.Page
    {
        List<NguoiDung_DAL> dsNguoiDung = new List<NguoiDung_DAL>();
        NguoiDungBL nguoiDung = new NguoiDungBL();
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
        protected void LayDSNguoiDungTheoMaQuyen()
        {
            string maquyen = cbb_PhanQuyen.SelectedItem.Value.ToString();
            dsNguoiDung = nguoiDung.LayDanhSachNguoiDungTheoMaQuyen(maquyen);

            grid_DanhSach.DataSource = dsNguoiDung;
            grid_DanhSach.DataBind();
        }
        protected void cbb_PhanQuyen_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string maquyen = cbb_PhanQuyen.SelectedItem.Value.ToString();
            }
        }

        protected void lbt_Xoa_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < grid_DanhSach.Rows.Count; i++)
            {
                GridViewRow row = grid_DanhSach.Rows[i];
                bool isChecked = ((CheckBox)row.Cells[0].FindControl("cbRows")).Checked;
                if (isChecked)
                {
                    TableCell taikhoan = grid_DanhSach.Rows[i].Cells[2];
                    
                    // Xóa dữ liệu
                    bool ok = nguoiDung.XoaNguoiDungTheoTaiKhoan(taikhoan.Text);

                    if (ok == true)
                    {
                        lb_Thongbao.Text = "Xóa Thành Công!!";
                        lb_Thongbao.Visible = true;
                        LayDSNguoiDungTheoMaQuyen();
                    }
                    else
                    {
                        lb_Thongbao.Text = "Xóa Thất bại!!";
                        lb_Thongbao.Visible = true;
                    }
                }
                else
                {
                    lb_Thongbao.Text = "Xóa Thất bại!!";
                    lb_Thongbao.Visible = true;
                }
            }
          
        }

        protected void lbt_Sua_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < grid_DanhSach.Rows.Count; i++)
            {
                GridViewRow row = grid_DanhSach.Rows[i];
                bool isChecked = ((CheckBox)row.Cells[0].FindControl("cbRows")).Checked;
                if (isChecked)
                {
                    TableCell taikhoan = grid_DanhSach.Rows[i].Cells[2];
                    string url = "";
                    url="SuaUser.aspx?taikhoan="+taikhoan.Text;
                    Response.Redirect(url);
                }
            }
            
        }

        protected void grid_DanhSach_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }

        protected void btn_Xem_Click(object sender, EventArgs e)
        {
            LayDSNguoiDungTheoMaQuyen();
        }

        //hàm này dùng để tô màu dòng đang chọn trong gridview cho đẹp
       /* protected void grid_DanhSach_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("style", "background-color: #FFFFFF; color: black;");
                e.Row.Attributes.Add("onmousein", "style.backgroundColor='#3399FF'");
                e.Row.Attributes.Add("onmouseout", "style.backgroundColor='#FFFFFF'");
            }
        }*/



    }
}